home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -screenplay- / shareware / amigapmars / primer.94 < prev    next >
Text File  |  1994-04-27  |  6KB  |  126 lines

  1. This primer assumes that you  are  familiar  with  corewar  under
  2. ICWS'88 rules.  For general information about corewar and ICWS'88
  3. consult the  corewar  archives  at  soda.berkeley.edu,  directory
  4. pub/corewar.  The primer is a casual introduction to the proposed
  5. ICWS'94 standard and will focus on comparing the old to the  pro-
  6. posed  new instruction set (refered to as Redcode '88 and Redcode
  7. '94 in the following). It is not a  complete  language  reference
  8. and  should  not  be used as a basis for ICWS'94 implementations.
  9. The file icws94.draft at soda in pub/corewar/documents should  be
  10. consulted for a more formal description of the proposed standard.
  11.  
  12. REDCODE'94
  13.      New in Redcode '94  are  instruction  modifiers,  additional
  14.      arithmetic  instructions  and  a  post-increment  addressing
  15.      mode. These will be discussed in turn. Redcode '94 is a true
  16.      superset  of  Redcode  '88, i.e. warriors written in Redcode
  17.      '88 should run without modification on a  MARS  that  imple-
  18.      ments Redcode '94.
  19.  
  20.  
  21. INSTRUCTION MODIFIERS
  22.      The most significant addition to Redcode '88 are instruction
  23.      modifiers  that  specify whether instructions operate on the
  24.      A-field, B-field,  or  a  whole  instrucution.  Redcode  '88
  25.      instructions  operate mostly on B-fields; exceptions to this
  26.      are ADD/SUB that can add/subtract both A-  and  B-fields  of
  27.      two  target  addresses  and  CMP  which  can  compare entire
  28.      instructions. As a result, the A-field  used  to  be  rather
  29.      difficult,  although  not  impossible to access. Instruction
  30.      modifiers in Redcode '94 allow easy access to  both  A-  and
  31.      B-fields. These are the modifiers and their meaning:
  32.  
  33.      .A   Instructions read and write A-fields.
  34.  
  35.      .B   Instructions read and write B-fields. It is easiest  to
  36.           think of .A as .AA and .B as .BB.
  37.  
  38.      .AB  Instructions read the A-field of the A-instruction  and
  39.           the B-field of the B-instruction and write to B-fields.
  40.  
  41.      .BA  Instructions read the B-field of the A-instruction  and
  42.           the A-field of the B-instruction and write to A-fields.
  43.  
  44.      .F   Instructions read both A- and B-fields of  the  the  A-
  45.           and  B-instruction and write to both A- and B-fields (A
  46.           to A and B to B).
  47.  
  48.      .X   Instructions read both A- and B-fields of  the  the  A-
  49.           and  B-instruction  and  write  to both A- and B-fields
  50.           exchanging fields (A to B and B to A).
  51.  
  52.      .I   Instructions read and write entire instructions.
  53.  
  54.      A- and B-instructions are the instructions pointed to by the
  55.      A-  and B-field, respectively. In immediate addressing mode,
  56.      A/B-instructions   are   the   current   instruction.    For
  57.      backwards-compatibilty  with Redcode '88, there is a mapping
  58.      of modifier-less instructions to instructions with modifiers
  59.      that takes the A and B-modes into account. E.g.
  60.  
  61.           MOV 0,1 translates into MOV.I 0,1
  62.           ADD 0,1 translates into ADD.F 0,1
  63.           MOV #0,1 translates into MOV.AB #0,1
  64.  
  65.      In Redcode '94 there are no illegal  instructions,  that  is
  66.      every  opcode  goes with every modifier and every addressing
  67.      mode    combination.    Non-sensical     combinations     of
  68.      opcode/modifier  are  treated  like  the closest combination
  69.      that makes sense, i.e.
  70.  
  71.           ADD.I behaves like ADD.F
  72.  
  73.      Special cases  are  branch  instructions  (JMP,JMZ,JNZ,DJN).
  74.      Redcode   '94   still  only  allows  to  branch  to  the  A-
  75.      instruction. If you read the draft, you will  find  that  it
  76.      cleverly  distinguishes  between  A-numbers  and A-pointers.
  77.      Branch instructions have A-pointers that are not subject  to
  78.      modifiers.  This  restriction  was  imposed to disallow all-
  79.      too-powerful bombs like JMP.F 0,0 and SPL.F 0,0.
  80.  
  81. MUL,DIV,MOD
  82.      These three new arithmetic opcodes supplement  ADD  and  SUB
  83.      from  Redcode  '88.   Some  experimentation with Redcode '94
  84.      will tell whether they encourage writing more  "intelligent"
  85.      warriors as Mark Durham suggests. The result of attempting a
  86.      division by zero in DIV and MOD is at the time of this writ-
  87.      ing  still  undefined.   pMARS  treats  attempting  a  zero-
  88.      division like executing a DAT instruction, i.e. the  offend-
  89.      ing  process is removed from the process queue. If two divi-
  90.      sions occur as in DIV.F, both divisions  are  attempted  and
  91.      core  is  updated for the division that succeeded. If either
  92.      division tried to divide by zero, the process is killed.
  93.  
  94. POST-INCREMENT INDIRECT
  95.      The post-increment indirect addressing mode,  symbolized  by
  96.      ">",  was  added  for symmetry. In contrast to pre-decrement
  97.      indirect, the field used for indirect addressing  is  incre-
  98.      mented before the effective address calculation takes place.
  99.      People have suggested that >  and  <  could  be  useful  for
  100.      implementing a stack (LIFO) data structure.
  101.  
  102. OTHERS
  103.      The ORG (ORiGin) pseudo-instruction is an alternative to END
  104.      for  specifying  the  execution  start.  The argument of ORG
  105.      points to  the  start  instruction  relative  to  the  first
  106.      instruction  of  the  warrior;  ORG  0  points  to the first
  107.      instruction.
  108.  
  109. EXAMPLES
  110.      A dwarf in Redcode '94 becomes:
  111.  
  112.                   ORG start
  113.           bomb    DAT.F 0,0
  114.           start   MOV.I bomb,3
  115.                   ADD.AB #3044,start
  116.                   JMP.B start
  117.  
  118.      Any modifier for the first and last instruction  would  work
  119.      here.  The  next  code fragment scrambles core by exchanging
  120.      A/B-fields:
  121.  
  122.           offset  DAT.I #99,#99
  123.           mix     MOV.X 10,20
  124.                   ADD.F offset,mix
  125.                   JMP.A mix
  126.